/*
CSS Browser Selector v0.4.0 (Nov 02, 2010)
Rafael Lima (http://rafael.adm.br)
http://rafael.adm.br/css_browser_selector
License: http://creativecommons.org/licenses/by/2.5/
Contributors: http://rafael.adm.br/css_browser_selector#contributors
*/
(function($){ 
    function css_browser_selector(u){
        var ua=u.toLowerCase(),is=function(t){
            return ua.indexOf(t)>-1
            },g='gecko',w='webkit',s='safari',o='opera',m='mobile',h=document.documentElement,b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3.5')?g+' ff3 ff3_5':is('firefox/3.6')?g+' ff3 ff3_6':is('firefox/3')?g+' ff3':is('gecko/')?g:is('opera')?o+(/version\/(\d+)/.test(ua)?' '+o+RegExp.$1:(/opera(\s|\/)(\d+)/.test(ua)?' '+o+RegExp.$2:'')):is('konqueror')?'konqueror':is('blackberry')?m+' blackberry':is('android')?m+' android':is('chrome')?w+' chrome':is('iron')?w+' iron':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?m+' j2me':is('iphone')?m+' iphone':is('ipod')?m+' ipod':is('ipad')?m+' ipad':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win'+(is('windows nt 6.0')?' vista':''):is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js'];
        c = b.join(' ');
        h.className += ' '+c;
        return c;
    };    
    css_browser_selector(navigator.userAgent);
})(jQuery);
;
(function($){ 
    $(function(){ // DOM ready
	
        // masque les hot news du footer
        $('#hot_news').hide();
        $('#lien_hot_news').click(function(){
            if($('#hot_news:visible').length){
                // scroll vers le haut avant de masquer le panneau (pour eviter les saccades)
                $.scrollTo('-=' + $('#hot_news').height() + 'px', 400, {
                    onAfter:function(){
                        $('#hot_news').hide();					
                    }
                });
        } else {
            $('#hot_news').show();
            $.scrollTo($('#ancre_bas'), 400);
        }
        });
		
    // message ie
    $('#message_ie .ferme_message').click(function(){
        $('#message_ie').fadeOut();
    });

    // petite flÃ¨che de la nav
    $('#main_header nav a.active-trail').append('<div class="fleche"></div>');

        // nav mobile
        $('#bt_nav').click(function(){
            $('#main_header nav').toggle();
        });

        // Chargement des tweets
        if ( $('#dernier_tweet .inner').length ) {
            $.getJSON('/ajax/xp_social_callback', function(data) {
                $(data).each(
                    function(key, item) {
                        if(typeof(item['text']) == 'string') {
                            
                            $('#dernier_tweet .inner').append('<a href="https://twitter.com/#!/XPRIME/status/' + item['id'] + '" target="_blank" class="last_tweet">' + item['text'] + '</a>');
                        }
                    }
                    );

                // roulement des tweets
                $('#dernier_tweet .inner .last_tweet').hide();
                nb_tweets = $('#dernier_tweet .inner .last_tweet').length;
                num_tweet = 1;
                $('#dernier_tweet .inner .last_tweet:nth-child(' + num_tweet + ')').show();
                setInterval(function(){
                    if(num_tweet < nb_tweets){
                        num_tweet++;
                    } else {
                        num_tweet = 1;
                    }
                    $('#dernier_tweet .inner .last_tweet').hide();
                    $('#dernier_tweet .inner .last_tweet:nth-child(' + num_tweet + ')').fadeIn();

                }, 5000);
            });
        }
		
        // Konami code !
        if ( window.addEventListener ) {
            var kkeys = [], konami = "38,38,40,40,37,39,37,39,66,65";
            window.addEventListener("keydown", function(e){
                kkeys.push( e.keyCode );
                if ( kkeys.toString().indexOf( konami ) >= 0 ){
					
                    $('body').append('<div id="konami"></div>');
					
                    $('#main_header nav a').html('Nyanyanyan!');
                    $('#main_header .autres_liens a').html('NYAN');
                    $('#lien_hot_news').html('Nyan!!');
                    $('#main_footer #dernier_tweet a').html('Nyan nyan nyanyanyanyan nyan nyanyanyanyanyanyanyanyan nyan nyanyanyanyan nyan nyanyanyanyanyanyanyanyan nyan!!!');
                    $('#main_footer .autres_liens .label').html('Nyan nyan nyan :');
					
                    $('body').append('<audio id="nyan_audio"><source src="/sites/all/themes/xpv6/music/nyan.mp3" /><source src="/sites/all/themes/xpv6/music/nyan.ogg" /></audio>');
					
                    nyan_music = $('#nyan_audio').get(0);
                    nyan_music.volume = .3;
                    nyan_music.play();
					
					
                    setInterval(function(){
                        $('#konami').css('left', Math.floor(Math.random()*1000) + 'px');
                        $('#konami').css('top', Math.floor(Math.random()*500) + 'px');
                    }, 500);
					
                }			
            }, true);
        }

        retaille_global();                     // calcul au chargement de la page
        $(window).scroll(retaille_global);     // calcul au dÃ©filement de la page
        $(window).resize(retaille_global);     // calcul au redimensionnement de la page

        window.scrollTo( 0, 1 );
		
    });

function retaille_global(){
    if(getWindowWidth() > 760){
        $('.menu-mlid-418 a').html('ID<span>/ Social media</span>');
        $('.menu-mlid-419 a').html('PROD<span>/ Brand content &amp; motion design</span>');
        $('.menu-mlid-420 a').html('MOBILE<span>/ Apps &amp; mobile web</span>');
    } else {
        $('.menu-mlid-418 a').html('XP ID');
        $('.menu-mlid-419 a').html('XP PROD');
        $('.menu-mlid-420 a').html('XP MOBILE');
    }
}



})(jQuery);

function getWindowHeight() {
    var windowHeight=0;
    if (typeof(window.innerHeight)=='number') {
        windowHeight=window.innerHeight;
    } else {
        if (document.documentElement && document.documentElement.clientHeight) {
            windowHeight = document.documentElement.clientHeight;
        } else {
            if (document.body && document.body.clientHeight) {
                windowHeight=document.body.clientHeight;
            }
        }
    }
    return windowHeight;
}

function getWindowWidth() {
    var windowWidth=0;
    if (typeof(window.innerWidth)=='number') {
        windowWidth=window.innerWidth;
    } else {
        if (document.documentElement && document.documentElement.clientWidth) {
            windowWidth = document.documentElement.clientWidth;
        } else {
            if (document.body && document.body.clientWidth) {
                windowWidth=document.body.clientWidth;
            }
        }
    }
    return windowWidth;
}

function getScrollerWidth() {
    var scr = null;
    var inn = null;
    var wNoScroll = 0;
    var wScroll = 0;

    // Outer scrolling div
    scr = document.createElement('div');
    scr.style.position = 'absolute';
    scr.style.top = '-1000px';
    scr.style.left = '-1000px';
    scr.style.width = '100px';
    scr.style.height = '50px';
    // Start with no scrollbar
    scr.style.overflow = 'hidden';

    // Inner content div
    inn = document.createElement('div');
    inn.style.width = '100%';
    inn.style.height = '200px';

    // Put the inner div in the scrolling div
    scr.appendChild(inn);
    // Append the scrolling div to the doc
    document.body.appendChild(scr);

    // Width of the inner div sans scrollbar
    wNoScroll = inn.offsetWidth;
    // Add the scrollbar
    scr.style.overflow = 'auto';
    // Width of the inner div width scrollbar
    wScroll = inn.offsetWidth;

    // Remove the scrolling div from the doc
    document.body.removeChild(
        document.body.lastChild);

    // Pixel width of the scroller
    return (wNoScroll - wScroll);
};
/**
 * jQuery.ScrollTo - Easy element scrolling using jQuery.
 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 5/25/2009
 * @author Ariel Flesler
 * @version 1.4.2
 *
 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
 */
;
(function(d){
    var k=d.scrollTo=function(a,i,e){
        d(window).scrollTo(a,i,e)
        };
        
    k.defaults={
        axis:'xy',
        duration:parseFloat(d.fn.jquery)>=1.3?0:1
        };
        
    k.window=function(a){
        return d(window)._scrollable()
        };
        
    d.fn._scrollable=function(){
        return this.map(function(){
            var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;
            if(!i)return a;
            var e=(a.contentWindow||a).document||a.ownerDocument||a;
            return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement
            })
        };
        
    d.fn.scrollTo=function(n,j,b){
        if(typeof j=='object'){
            b=j;
            j=0
            }
            if(typeof b=='function')b={
            onAfter:b
        };
        
        if(n=='max')n=9e9;
        b=d.extend({},k.defaults,b);
        j=j||b.speed||b.duration;
        b.queue=b.queue&&b.axis.length>1;
        if(b.queue)j/=2;
        b.offset=p(b.offset);
        b.over=p(b.over);
        return this._scrollable().each(function(){
            var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');
            switch(typeof f){
                case'number':case'string':
                    if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){
                    f=p(f);
                    break
                }
                f=d(f,this);
                case'object':
                    if(f.is||f.style)s=(f=d(f)).offset()
                    }
                    d.each(b.axis.split(''),function(a,i){
                var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);
                if(s){
                    g[c]=s[h]+(u?0:l-r.offset()[h]);
                    if(b.margin){
                        g[c]-=parseInt(f.css('margin'+e))||0;
                        g[c]-=parseInt(f.css('border'+e+'Width'))||0
                        }
                        g[c]+=b.offset[h]||0;
                    if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]
                        }else{
                    var o=f[h];
                    g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o
                    }
                    if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);
                if(!a&&b.queue){
                    if(l!=g[c])t(b.onAfterFirst);
                    delete g[c]
                }
            });
        t(b.onAfter);
            function t(a){
            r.animate(g,j,b.easing,a&&function(){
                a.call(this,n,b)
                })
            }
        }).end()
    };
    
k.max=function(a,i){
    var e=i=='x'?'Width':'Height',h='scroll'+e;
    if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();
    var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;
    return Math.max(l[h],m[h])-Math.min(l[c],m[c])
    };
    
function p(a){
    return typeof a=='object'?a:{
        top:a,
        left:a
    }
}
})(jQuery);
;
